 <?php
include 'db.php';

$username=$_GET['u'];
$password=md5($_GET['p']);
$email=$_GET['e'];
$ip=$_SERVER['REMOTE_ADDR'];
$usable = "true";
	if($username != "" && $password != "" && $email != "")
	{
	    $q=mysql_query("SELECT * FROM login WHERE (username='$username' OR email='$email')");
	    while($data = mysql_fetch_row($q)){
	        if($data[3] == $email){
                echo "Reason: Email is already in use, please pick another.".PHP_EOL;
                $usable = "false";
                break;
            }
	        if($data[1] == $username){
                echo "Reason: Username is already in use".PHP_EOL;
                $usable = "false";
                break;
            }
        }
        if($usable == "true"){
            if (mysql_query("INSERT INTO login(username, password, email, ip,totalrating, ratingcount) VALUES('$username','$password','$email','$ip',0,0)"))
                            echo "Account Created";
                        else
                            echo "Error: " . mysql_error();
        }
	}
	else
	    echo "Bad account";

mysql_close($link);
?>
